"""
参考：
    https://dormousehole.readthedocs.io/en/latest/
    https://dormousehole.readthedocs.io/en/latest/quickstart.html
    https://dormousehole.readthedocs.io/en/latest/tutorial/index.html
    https://dormousehole.readthedocs.io/en/latest/patterns/index.html
"""
from flask import Flask
from flask import render_template
from flask import make_response

app = Flask(__name__)

@app.route("/")
def hello():
    return "<p>Hello, World!</p>"

@app.route("/hh")
def hh():
    return "hh"

@app.route("/api")
def api():
    return {
        "code": 0,
        "data": {"f1":1, "f2":2}
    }


def bootstrap_loadLogger(app):
    """
        设置日志路径.级别。
        参考: https://blog.csdn.net/lvbu89757/article/details/95231967
    """
    import logging
    from logging.handlers import RotatingFileHandler
    logging.basicConfig(level=logging.DEBUG)
    file_log_handler = RotatingFileHandler('logs/log', maxBytes=1024 * 1024, backupCount=10)
    formatter = logging.Formatter('%(levelname)s %(filename)s %(lineno)d %(message)s')
    file_log_handler.setFormatter(formatter)
    logging.getLogger().addHandler(file_log_handler)
    """
    app.logger.debug('test, A value for debugging')
    app.logger.warning('test, A value for warning')
    """

bootstrap_loadLogger(app)
if __name__ == "__main__":
    app.run()
